package com.cjm.one.webmanager.controller.goods;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.result.Result;
import com.cjm.one.model.goods.entity.GoodsBrand;
import com.cjm.one.model.goods.vo.GoodsBrandVo;
import com.cjm.one.webmanager.service.goods.GoodsBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@Slf4j
@Tag(name = "2-商品品牌管理", description = "商品品牌管理")
@RequestMapping("/manager/goods/brand")
public class GoodsBrandController {
    @Resource
    private GoodsBrandService goodsBrandService;

    @GetMapping("/list")
    @Operation(summary = "分页查询" )
    public Result<Page<GoodsBrandVo>> page(@RequestParam(name = "current", defaultValue = "1") Integer current,
                                           @RequestParam(name = "size", defaultValue = "10") Integer size
            , @RequestParam(name = "name",required = false) String name){
        return Result.ok(goodsBrandService.pageByName(current, size, name));
    }
    @GetMapping("/list/all")
    @Operation(summary = "查询所有" )
    public Result<ArrayList<GoodsBrandVo>> listAll(){
        return Result.ok(goodsBrandService.listAll());
    }
    @GetMapping("/{id}")
    @Operation(summary = "根据id查询" )
    public Result<GoodsBrandVo> getById(@PathVariable(name = "id") Long id) {
        return Result.ok(goodsBrandService.getById(id));
    }
    @PostMapping
    @Operation(summary = "新增" )
    public Result<Boolean> save(@RequestBody GoodsBrand goodBrand) {
        return Result.ok(goodsBrandService.save(goodBrand));
    }
    @PutMapping
    @Operation(summary = "修改" )
    public Result<Boolean> update(@RequestBody GoodsBrand goodBrand) {
        return Result.ok(goodsBrandService.updateById(goodBrand));
    }
    @DeleteMapping("/{id}")
    @Operation(summary = "删除" )
    public Result<Boolean> delete(@PathVariable(name = "id") Long id) {
        return Result.ok(goodsBrandService.removeById(id));
    }
}
